<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition>
        <p:outputPanel id="pnl" styleClass="noborder">
            <p:dataTable id="tbl_participants" var="p" rowIndexVar="row" value="#{showClassRoomBean.participantsForClassRoom()}" rowKey="#{p.id}"
                         selection="#{editParticipants.selectedParticipant}" selectionMode="single" rowStyleClass="#{!p.accepted ? 'invited' : null}">
                <p:ajax event="rowSelect" listener="#{editParticipants.onRowSelect}" update=":pnl"/>
                <p:ajax event="rowUnselect" listener="#{editParticipants.onRowUnselect}" update=":pnl"/>
                <p:column headerText="#{msg.editparticipants_tbl_p_col_nr_header}">
                    <h:outputText value="#{row + 1}"/>
                </p:column>
                <p:column headerText="#{msg.editparticipants_tbl_p_col_fn_header}">
                    <h:outputText value="#{p.user.firstname}"/>
                </p:column>
                <p:column headerText="#{msg.editparticipants_tbl_p_col_ln_header}">
                    <h:outputText value="#{p.user.lastname}"/>
                </p:column>
                <p:column headerText="#{msg.editparticipants_tbl_p_col_mail_header}">
                    <h:outputText value="#{p.user.email}"/>                    
                </p:column>
                <p:column headerText="#{msg.editparticipants_tbl_p_col_rl_header}">
                    <h:outputText value="#{p.classRoomRole}"/>
                </p:column>
            </p:dataTable>
            <h:outputText id="lbl_tbl_p" styleClass="invited" value="#{msg.editparticipants_lbl_tbl_p_value}"/>
            <p:separator/>
            <p:outputPanel id="pnl_edit" rendered="#{editParticipants.showEdit}">
                <h:form>
                    <p:panelGrid columns="2" styleClass="noborder">
                        <h:outputText id="lbl_edit_fn" value="#{msg.editparticipants_lbl_edit_fn}"/>
                        <h:outputText id="txt_edit_fn" value="#{editParticipants.selectedParticipant.user.firstname}"/>
                        <h:outputText id="lbl_edit_ln" value="#{msg.editparticipants_lbl_edit_ln}"/>
                        <h:outputText id="txt_edit_ln" value="#{editParticipants.selectedParticipant.user.lastname}"/>
                        <h:outputText id="lbl_edit_role" value="#{msg.editparticipants_som_edit_role}"/>
                        <p:selectOneMenu id="som_edit_role" value="#{editParticipants.selectedParticipant.classRoomRole}" converter="#{ClassRoomRoleConverter}">
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_admin}" itemValue="ADMIN"/>
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_writer}" itemValue="WRITER"/>
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_reader}" itemValue="READER"/>
                        </p:selectOneMenu>
                    </p:panelGrid>
                    <p:separator/>
                    <p:commandButton id="btn_save" value="#{msg.btn_save}" actionListener="#{editParticipants.save}" process="@parent" update=":pnl"/>
                    <p:commandButton id="btn_cancel" value="#{msg.btn_cancel}" actionListener="#{editParticipants.cancel}" update=":pnl" process="@this"/>
                </h:form>
            </p:outputPanel>
            <p:outputPanel id="pnl_inv" rendered="#{!editParticipants.showEdit}">
                <h:form>
                    <p:panelGrid columns="3" styleClass="noborder">
                        <p:outputLabel id="lbl_inv_mail" for="txt_inv_mail" value="#{msg.editparticipants_lbl_inv_mail}"/>
                        <p:inputText id="txt_inv_mail" value="#{editParticipants.email}" binding="#{editParticipants.emailFiled}" required="true" requiredMessage="#{msg.editparticipants_txt_inv_reqMes}"/>
                        <p:message for="txt_inv_mail" showDetail="true"/>
                        <h:outputText id="lbl_inv_role" value="#{msg.editparticipants_som_edit_role}"/>
                        <p:selectOneMenu id="som_inv_role" value="#{editParticipants.newParticipants.classRoomRole}" converter="#{ClassRoomRoleConverter}">
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_admin}" itemValue="ADMIN"/>
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_writer}" itemValue="WRITER"/>
                            <f:selectItem itemLabel="#{msg.editparticipants_lbl_som_reader}" itemValue="READER"/>
                        </p:selectOneMenu>
                    </p:panelGrid>
                    <p:separator/>
                    <p:commandButton id="btn_inv" value="#{msg.btn_inv}" actionListener="#{editParticipants.invite}" process="@parent" update=":pnl">
                        <p:resetInput target=":pnl_inv"/>
                    </p:commandButton>
                    <p:commandButton id="btn_cancel" value="#{msg.btn_cancel}" actionListener="#{editParticipants.cancel}" update=":pnl" process="@this">
                        <p:resetInput target=":pnl_inv"/>
                    </p:commandButton>
                </h:form>
            </p:outputPanel>
        </p:outputPanel>
    </ui:composition>
</html>